#define _CRT_SECURE_NO_WARNINGS 1

//用栈实现队列法二
typedef struct
{
    Stack pushstack;
    Stack popstack;
} MyQueue;

//队列的初始化
MyQueue* myQueueCreate()
{
    MyQueue* mq = (MyQueue*)malloc(sizeof(MyQueue));
    StackInit(&(mq->pushstack));
    StackInit(&(mq->popstack));

    return mq;
}

void myQueuePush(MyQueue* obj, int x)
{
    //直接向插入栈插入数据
    StackPush(&(obj->pushstack), x);
}

int myQueuePop(MyQueue* obj)
{
    int top = myQueuePeek(obj);
    StackPop(&(obj->popstack));
    return top;
}

int myQueuePeek(MyQueue* obj)
{
    //判断删除栈是否为空
    if (StackEmpty(&(obj->popstack)))
    {
        //如果为空从插入栈导数据
        while (!StackEmpty(&(obj->pushstack)))
        {
            StackPush(&(obj->popstack), GetStackTop(&(obj->pushstack)));
            StackPop(&(obj->pushstack));
        }
    }
    //删除栈不为空直接返回删除栈的栈顶元素
    return GetStackTop(&(obj->popstack));
}

bool myQueueEmpty(MyQueue* obj)
{
    return StackEmpty(&(obj->pushstack)) && StackEmpty(&(obj->popstack));
}

//队列的销毁
void myQueueFree(MyQueue* obj)
{
    StackDestory(&(obj->pushstack));
    StackDestory(&(obj->popstack));

    free(obj);
    obj = NULL;
}

int main()
{
    MyQueue* mq = myQueueCreate();

    myQueuePush(mq, 1);
    myQueuePush(mq, 2);
    myQueuePush(mq, 3);
    myQueuePush(mq, 4);

    //printf("%d\n", myQueuePeek(mq));
    printf("%d\n", myQueuePop(mq));
    return 0;
}